import { InjectionToken } from "tsyringe";
import { IListener, IListenerAll } from "../core/listener";
import { ISender } from "../core/sender";
import { tryGetAll } from "../utils/tryGetAll";
import { IOnInit, IOnDestory } from "../core/lifecycle";
import { tryGet, tryGetSafe } from "../utils/tryGet";
import { IConfig } from "../core/config";
import { ICloudWs } from "../core/ws";
import { ITask } from "../core/task";

export const SHOW_CONSOLE: InjectionToken<boolean> = `SHOW_CONSOLE`
export const PUSH_TOKEN: InjectionToken<string> = `PUSH_TOKEN`

export function getShowConsole(){
    return tryGetSafe(SHOW_CONSOLE, false)
}

export function getPushToken(){
    return tryGet(PUSH_TOKEN)
}

export interface ICallWeb<T = any, R = any> {
    (name: string, data: T): Promise<R>
}
export const CALL_WEB: InjectionToken<ICallWeb> = `CALL_WEB`
export function getCallWeb() {
    return tryGet(CALL_WEB)
}
export const CLOUD_WS: InjectionToken<ICloudWs> = `CLOUD_WS`
export function getCloudWs() {
    return tryGet(CLOUD_WS)
}
// 监听者
export const LISTENERS: InjectionToken<IListener> = `LISTENERS`
export const LISTENER_ALL: InjectionToken<IListenerAll> = `LISTENER_ALL`

// 发送者
export const SENDER: InjectionToken<ISender> = `SENDER`
// 系统启动钩子
export const ON_INITS: InjectionToken<IOnInit> = `ON_INITS`
// 系统注销钩子
export const ON_DESTORY: InjectionToken<IOnDestory> = `ON_DESTORY`
// 配置服务
export const CONFIG: InjectionToken<IConfig> = `CONFIG`

export const APPLICATION_INITIALIZATION: InjectionToken<`0` | `1`> = `APPLICATION_INITIALIZATION`

export const TASK: InjectionToken<ITask> = `TASK`


export function getTask() {
    return tryGet(TASK)
}

export function getConfig() {
    return tryGet(CONFIG)
}

export function getSender() {
    return tryGet(SENDER)
}

export function getAllListener() {
    return tryGetAll(LISTENERS)
}

export function getAllOnInit() {
    return tryGetAll(ON_INITS)
}

export function getAllOnDestory() {
    return tryGetAll(ON_DESTORY)
}
